package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.dto.pagedto.OperationPageDto;
import com.heima.mapper.OperateLogMapper;
import com.heima.pojo.OperateLog;
import com.heima.service.OperationLogService;
import com.heima.vo.PageResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class OperationLogServiceImpl implements OperationLogService {

    private final OperateLogMapper operateLogMapper;

    /**
     * 日志记录分页查询
     * @param dto
     * @return
     */
    @Override
    public PageResult queryOperationLog(OperationPageDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<OperateLog> page = operateLogMapper.queryOperationLog(dto);
        PageResult pageResult = new PageResult();
        pageResult.setTotal(page.getTotal());
        pageResult.setRows(page.getResult());
        return pageResult;
    }

    /**
     * 批量删除日志记录
     * @param ids
     */
    @Override
    public void deleteLog(List<Integer> ids) {
        operateLogMapper.deleteLog(ids);
    }

    /**
     * 清空日志
     */
    @Override
    public void cleanLog() {
        operateLogMapper.cleanLog();
    }

}
